package com.nmsl.system.surcharge.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.system.surcharge.domain.Surcharge;
import com.nmsl.system.surcharge.service.ISurchargeService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 附加费用Controller
 * 
 * @author gmh
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/system/surcharge")
public class SurchargeController extends BaseController
{
    @Autowired
    private ISurchargeService surchargeService;

    /**
     * 查询附加费用列表
     */
    @PreAuthorize("@ss.hasPermi('system:surcharge:list')")
    @GetMapping("/list")
    public TableDataInfo list(Surcharge surcharge)
    {
        startPage();
        List<Surcharge> list = surchargeService.selectSurchargeList(surcharge);
        return getDataTable(list);
    }

    /**
     * 导出附加费用列表
     */
    @PreAuthorize("@ss.hasPermi('system:surcharge:export')")
    @Log(title = "附加费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Surcharge surcharge)
    {
        List<Surcharge> list = surchargeService.selectSurchargeList(surcharge);
        ExcelUtil<Surcharge> util = new ExcelUtil<Surcharge>(Surcharge.class);
        util.exportExcel(response, list, "附加费用数据");
    }

    /**
     * 获取附加费用详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:surcharge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(surchargeService.selectSurchargeById(id));
    }

    /**
     * 新增附加费用
     */
    @PreAuthorize("@ss.hasPermi('system:surcharge:add')")
    @Log(title = "附加费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Surcharge surcharge)
    {
        return toAjax(surchargeService.insertSurcharge(surcharge));
    }

    /**
     * 修改附加费用
     */
    @PreAuthorize("@ss.hasPermi('system:surcharge:edit')")
    @Log(title = "附加费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Surcharge surcharge)
    {
        return toAjax(surchargeService.updateSurcharge(surcharge));
    }

    /**
     * 删除附加费用
     */
    @PreAuthorize("@ss.hasPermi('system:surcharge:remove')")
    @Log(title = "附加费用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surchargeService.deleteSurchargeByIds(ids));
    }
}
